<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 300px;
            border-bottom: 1px solid rgba(211, 209, 209, 0.596);
            margin: 100px auto;
            position: relative;
        }
        .box input{
            width: 270px;
            height: 30px;
            border: 0;
            outline: none;
        }
        .box img{
            width: 25px;
            height: 25px;
            position: absolute;
            margin-left: 270px;
        }
    </style>
</head>
<body>
    <div class="box">
        <label for="">
            <img src="/Users/D盘/JavaScript练习/picture/close.jpeg" alt="">
        </label>
        <input type="password" name="" id="">
    </div>
    <script>
        var img = document.querySelector('img');
        var input = document.querySelector('input');
        var flag = 0;
        img.onclick = function(){
            if(flag == 0){
                input.type = "text";
                img.src = "/Users/D盘/JavaScript练习/picture/open.jpeg";
                flag = 1;
            }else{
                input.type = "password";
                img.src = "/Users/D盘/JavaScript练习/picture/close.jpeg";
                flag = 0;
            }
            
        }
    </script>
</body>
</html>